home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / sound / cheap studio / cheap_studio.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  21.3 KB  |  689 lines

  1. /*
  2.     File:        Cheap_Studio.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/13/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #include <SoundInput.h>
  24. #include <Drag.h>
  25. #include <Gestalt.h>
  26.  
  27. #include "SAL_Public.h"
  28. #include "SimpleApp_Sound.h"
  29.  
  30. typedef struct {
  31.         long            sanitycheck;
  32.         SPBPtr            recordRec;
  33.         Ptr                pb0,
  34.                         pb1;
  35.         Ptr                recBuffer0,
  36.                         recBuffer1;
  37.         Fixed            sampleRate;
  38.         OSType            compression;
  39.         unsigned long    totalBytes;
  40.         long            myA5,
  41.                         devBuffer,
  42.                         soundRefNum;
  43.         short            whichBuffer,
  44.                         fileRefNum,
  45.                         numChannels,
  46.                         sampleSize;
  47.         OSErr            theErr;        //last error returned by SPBRecord or PBWrite
  48. } Vars, *VarsPtr;
  49.  
  50. OSErr    PrepairToRecordToDisk (VarsPtr myVars);
  51. OSErr    RecordToDisk (VarsPtr);
  52. OSErr    FinishRecording (VarsPtr myVars);
  53.  
  54. Vars                myVars;
  55.  
  56. /*-----------------------------------------------------------------------*/
  57. static pascal OSErr    MyIdleProc (const EventRecord *evt)
  58. {
  59. #ifndef __SC__
  60. #pragma unused (evt)
  61. #endif
  62.  
  63.     if (sound1Playing && ASoundIsDone (mySoundInfo1) == true) {
  64.         ASoundDonePlaying (mySoundInfo1, nil);
  65.         gSAL_CurrentControl = playButton1;
  66.         sound1Playing = false;
  67.         SAL_SetTitle ("\pPlay");
  68.     }
  69.     if (sound2Playing && ASoundIsDone (mySoundInfo2) == true) {
  70.         ASoundDonePlaying (mySoundInfo2, nil);
  71.         gSAL_CurrentControl = playButton2;
  72.         sound2Playing = false;
  73.         SAL_SetTitle ("\pPlay");
  74.     }
  75.     if (sound3Playing && ASoundIsDone (mySoundInfo3) == true) {
  76.         ASoundDonePlaying (mySoundInfo3, nil);
  77.         gSAL_CurrentControl = playButton3;
  78.         sound3Playing = false;
  79.         SAL_SetTitle ("\pPlay");
  80.     }
  81.     if (sound4Playing && ASoundIsDone (mySoundInfo4) == true) {
  82.         ASoundDonePlaying (mySoundInfo4, nil);
  83.         gSAL_CurrentControl = playButton4;
  84.         sound4Playing = false;
  85.         SAL_SetTitle ("\pPlay");
  86.     }
  87.     if (sound5Playing && ASoundIsDone (mySoundInfo5) == true) {
  88.         ASoundDonePlaying (mySoundInfo5, nil);
  89.         gSAL_CurrentControl = playButton5;
  90.         sound5Playing = false;
  91.         SAL_SetTitle ("\pPlay");
  92.     }
  93.     if (sound6Playing && ASoundIsDone (mySoundInfo6) == true) {
  94.         ASoundDonePlaying (mySoundInfo6, nil);
  95.         gSAL_CurrentControl = playButton6;
  96.         sound6Playing = false;
  97.         SAL_SetTitle ("\pPlay");
  98.     }
  99.     if (playAll == true) {
  100.         if (!sound1Playing && !sound2Playing && !sound3Playing && !sound4Playing && !sound5Playing && !sound6Playing) {
  101.             gSAL_CurrentControl = playAllButton;
  102.             SAL_SetTitle ("\pPlay All");
  103.             playAll = false;
  104.         }
  105.     } else {
  106.         if (sound1Playing && sound2Playing && sound3Playing && sound4Playing && sound5Playing && sound6Playing) {
  107.             gSAL_CurrentControl = playAllButton;
  108.             SAL_SetTitle ("\pStop All");
  109.             playAll = true;
  110.         }
  111.     }
  112.     return noErr;
  113. }
  114.  
  115. /*-----------------------------------------------------------------------*/
  116. static pascal OSErr DoPlay1(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  117. {
  118.     OSErr    theErr;
  119.  
  120. #pragma unused (pButtonItemRef,pModifiers)
  121.  
  122.     if (sound1Set == false) {
  123.         theErr = ASoundGetFileToPlay (mySoundInfo1);
  124.         theErr = ASoundReadyForPlaying (mySoundInfo1, nil);
  125.         if (theErr == noErr) {
  126.             sound1Set = true;
  127.             sound1Playing = false;
  128.             SAL_SetTitle ("\pPlay");
  129.         }
  130.     } else {
  131.         if (sound1Playing == false) {
  132.             if (playAll == true) {
  133.                 SndCommand    theCmd;
  134.                 SndChannelPtr    theChan;
  135.  
  136.                 theChan = ASoundGetChan (mySoundInfo1);
  137.                 theCmd.cmd = syncCmd;
  138.                 theCmd.param1 = soundsToSync;
  139.                 theCmd.param2 = 'scme';
  140.                 theErr = SndDoImmediate (theChan, &theCmd);
  141.             }
  142.             theErr = ASoundPlay (mySoundInfo1);
  143.             if (theErr == noErr) {
  144.                 sound1Playing = true;
  145.                 gSAL_CurrentControl = playButton1;
  146.                 SAL_SetTitle ("\pStop");
  147.             }
  148.         } else {
  149.             theErr = ASoundStop (mySoundInfo1);
  150.         }
  151.     }
  152.  
  153.     return theErr;
  154. }
  155.  
  156. /*-----------------------------------------------------------------------*/
  157. static pascal OSErr DoPlay2(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  158. {
  159.     OSErr    theErr;
  160.  
  161. #pragma unused (pButtonItemRef,pModifiers)
  162.  
  163.     if (sound2Set == false) {
  164.         theErr = ASoundGetFileToPlay (mySoundInfo2);
  165.         theErr = ASoundReadyForPlaying (mySoundInfo2, nil);
  166.         if (theErr == noErr) {
  167.             sound2Set = true;
  168.             sound2Playing = false;
  169.             SAL_SetTitle ("\pPlay");
  170.         }
  171.     } else {
  172.         if (sound2Playing == false) {
  173.             if (playAll == true) {
  174.                 SndCommand    theCmd;
  175.                 SndChannelPtr    theChan;
  176.  
  177.                 theChan = ASoundGetChan (mySoundInfo2);
  178.                 theCmd.cmd = syncCmd;
  179.                 theCmd.param1 = soundsToSync;
  180.                 theCmd.param2 = 'scme';
  181.                 theErr = SndDoImmediate (theChan, &theCmd);
  182.             }
  183.             theErr = ASoundPlay (mySoundInfo2);
  184.             if (theErr == noErr) {
  185.                 sound2Playing = true;
  186.                 gSAL_CurrentControl = playButton2;
  187.                 SAL_SetTitle ("\pStop");
  188.             }
  189.         } else {
  190.             theErr = ASoundStop (mySoundInfo2);
  191.         }
  192.     }
  193.     return theErr;
  194. }
  195.  
  196. /*-----------------------------------------------------------------------*/
  197. static pascal OSErr DoPlay3(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  198. {
  199.     OSErr    theErr;
  200.  
  201. #pragma unused (pButtonItemRef,pModifiers)
  202.  
  203.     if (sound3Set == false) {
  204.         theErr = ASoundGetFileToPlay (mySoundInfo3);
  205.         theErr = ASoundReadyForPlaying (mySoundInfo3, nil);
  206.         if (theErr == noErr) {
  207.             sound3Set = true;
  208.             sound3Playing = false;
  209.             SAL_SetTitle ("\pPlay");
  210.         }
  211.     } else {
  212.         if (sound3Playing == false) {
  213.             if (playAll == true) {
  214.                 SndCommand    theCmd;
  215.                 SndChannelPtr    theChan;
  216.  
  217.                 theChan = ASoundGetChan (mySoundInfo3);
  218.                 theCmd.cmd = syncCmd;
  219.                 theCmd.param1 = soundsToSync;
  220.                 theCmd.param2 = 'scme';
  221.                 theErr = SndDoImmediate (theChan, &theCmd);
  222.             }
  223.             theErr = ASoundPlay (mySoundInfo3);
  224.             if (theErr == noErr) {
  225.                 sound3Playing = true;
  226.                 gSAL_CurrentControl = playButton3;
  227.                 SAL_SetTitle ("\pStop");
  228.             }
  229.         } else {
  230.             theErr = ASoundStop (mySoundInfo3);
  231.         }
  232.     }
  233.     return theErr;
  234. }
  235.  
  236. /*-----------------------------------------------------------------------*/
  237. static pascal OSErr DoPlay4 (const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  238. {
  239.     OSErr    theErr;
  240.  
  241. #pragma unused (pButtonItemRef,pModifiers)
  242.  
  243.     if (sound4Set == false) {
  244.         theErr = ASoundGetFileToPlay (mySoundInfo4);
  245.         theErr = ASoundReadyForPlaying (mySoundInfo4, nil);
  246.         if (theErr == noErr) {
  247.             sound4Set = true;
  248.             sound4Playing = false;
  249.             SAL_SetTitle ("\pPlay");
  250.         }
  251.     } else {
  252.         if (sound4Playing == false) {
  253.             if (playAll == true) {
  254.                 SndCommand    theCmd;
  255.                 SndChannelPtr    theChan;
  256.  
  257.                 theChan = ASoundGetChan (mySoundInfo4);
  258.                 theCmd.cmd = syncCmd;
  259.                 theCmd.param1 = soundsToSync;
  260.                 theCmd.param2 = 'scme';
  261.                 theErr = SndDoImmediate (theChan, &theCmd);
  262.             }
  263.             theErr = ASoundPlay (mySoundInfo4);
  264.             if (theErr == noErr) {
  265.                 sound4Playing = true;
  266.                 gSAL_CurrentControl = playButton4;
  267.                 SAL_SetTitle ("\pStop");
  268.             }
  269.         } else {
  270.             theErr = ASoundStop (mySoundInfo4);
  271.         }
  272.     }
  273.     return theErr;
  274. }
  275.  
  276. /*-----------------------------------------------------------------------*/
  277. static pascal OSErr DoPlay5(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  278. {
  279.     OSErr    theErr;
  280.  
  281. #pragma unused (pButtonItemRef,pModifiers)
  282.  
  283.     if (sound5Set == false) {
  284.         theErr = ASoundGetFileToPlay (mySoundInfo5);
  285.         theErr = ASoundReadyForPlaying (mySoundInfo5, nil);
  286.         if (theErr == noErr) {
  287.             sound5Set = true;
  288.             sound5Playing = false;
  289.             SAL_SetTitle ("\pPlay");
  290.         }
  291.     } else {
  292.         if (sound5Playing == false) {
  293.             if (playAll == true) {
  294.                 SndCommand    theCmd;
  295.                 SndChannelPtr    theChan;
  296.  
  297.                 theChan = ASoundGetChan (mySoundInfo5);
  298.                 theCmd.cmd = syncCmd;
  299.                 theCmd.param1 = soundsToSync;
  300.                 theCmd.param2 = 'scme';
  301.                 theErr = SndDoImmediate (theChan, &theCmd);
  302.             }
  303.             theErr = ASoundPlay (mySoundInfo5);
  304.             if (theErr == noErr) {
  305.                 sound5Playing = true;
  306.                 gSAL_CurrentControl = playButton5;
  307.                 SAL_SetTitle ("\pStop");
  308.             }
  309.         } else {
  310.             theErr = ASoundStop (mySoundInfo5);
  311.         }
  312.     }
  313.  
  314.     return theErr;
  315. }
  316.  
  317. /*-----------------------------------------------------------------------*/
  318. static pascal OSErr DoPlay6(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  319. {
  320.     OSErr    theErr;
  321.  
  322. #pragma unused (pButtonItemRef,pModifiers)
  323.  
  324.     if (sound6Set == false) {
  325.         theErr = ASoundGetFileToPlay (mySoundInfo6);
  326.         theErr = ASoundReadyForPlaying (mySoundInfo6, nil);
  327.         if (theErr == noErr) {
  328.             sound6Set = true;
  329.             sound6Playing = false;
  330.             SAL_SetTitle ("\pPlay");
  331.         }
  332.     } else {
  333.         if (sound6Playing == false) {
  334.             if (playAll == true) {
  335.                 SndCommand    theCmd;
  336.                 SndChannelPtr    theChan;
  337.  
  338.                 theChan = ASoundGetChan (mySoundInfo6);
  339.                 theCmd.cmd = syncCmd;
  340.                 theCmd.param1 = soundsToSync;
  341.                 theCmd.param2 = 'scme';
  342.                 theErr = SndDoImmediate (theChan, &theCmd);
  343.             }
  344.             theErr = ASoundPlay (mySoundInfo6);
  345.             if (theErr == noErr) {
  346.                 sound6Playing = true;
  347.                 gSAL_CurrentControl = playButton6;
  348.                 SAL_SetTitle ("\pStop");
  349.             }
  350.         } else {
  351.             theErr = ASoundStop (mySoundInfo6);
  352.         }
  353.     }
  354.     return theErr;
  355. }
  356.  
  357. /*-----------------------------------------------------------------------*/
  358. static pascal OSErr DoPlayAll(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  359. {
  360.     OSErr    theErr;
  361.  
  362.     if (playAll == false) {
  363.         playAll = true;
  364.         soundsToSync = 0;
  365.         if (sound1Set) soundsToSync++;
  366.         if (sound2Set) soundsToSync++;
  367.         if (sound3Set) soundsToSync++;
  368.         if (sound4Set) soundsToSync++;
  369.         if (sound5Set) soundsToSync++;
  370.         if (sound6Set) soundsToSync++;
  371.         if (sound1Set == true && sound1Playing == false) { theErr = DoPlay1(pButtonItemRef,pModifiers);soundsToSync--;}
  372.         if (sound2Set == true && sound2Playing == false) { theErr = DoPlay2(pButtonItemRef,pModifiers);soundsToSync--;}
  373.         if (sound3Set == true && sound3Playing == false) { theErr = DoPlay3(pButtonItemRef,pModifiers);soundsToSync--;}
  374.         if (sound4Set == true && sound4Playing == false) { theErr = DoPlay4(pButtonItemRef,pModifiers);soundsToSync--;}
  375.         if (sound5Set == true && sound5Playing == false) { theErr = DoPlay5(pButtonItemRef,pModifiers);soundsToSync--;}
  376.         if (sound6Set == true && sound6Playing == false) { theErr = DoPlay6(pButtonItemRef,pModifiers);}
  377.         gSAL_CurrentControl = playAllButton;
  378.         SAL_SetTitle ("\pStop All");
  379.     } else {
  380.         playAll = false;
  381.         if (sound1Set == true && sound1Playing == true) theErr = DoPlay1(pButtonItemRef,pModifiers);
  382.         if (sound2Set == true && sound2Playing == true) theErr = DoPlay2(pButtonItemRef,pModifiers);
  383.         if (sound3Set == true && sound3Playing == true) theErr = DoPlay3(pButtonItemRef,pModifiers);
  384.         if (sound4Set == true && sound4Playing == true) theErr = DoPlay4(pButtonItemRef,pModifiers);
  385.         if (sound5Set == true && sound5Playing == true) theErr = DoPlay5(pButtonItemRef,pModifiers);
  386.         if (sound6Set == true && sound6Playing == true) theErr = DoPlay6(pButtonItemRef,pModifiers);
  387.         gSAL_CurrentControl = playAllButton;
  388.         SAL_SetTitle ("\pPlay All");
  389.     }
  390.     return theErr;
  391. }
  392.  
  393. /*-----------------------------------------------------------------------*/
  394. static pascal OSErr DoRecord (const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  395. {
  396.     OSErr    theErr;
  397.  
  398.     if (!recording) {
  399.         if (!prepairedToRecord) {
  400.             theErr = PrepairToRecordToDisk (&myVars);
  401.             if (theErr == noErr) {
  402.                 prepairedToRecord = true;
  403.                 gSAL_CurrentControl = recordButton;
  404.                 SAL_SetTitle ("\pRecord&Play");
  405.             }
  406.         } else {
  407.             DoPlayAll(pButtonItemRef,pModifiers);
  408.             theErr = RecordToDisk (&myVars);
  409.             recording = true;
  410.             gSAL_CurrentControl = recordButton;
  411.             SAL_SetTitle ("\pStop record");
  412.         }
  413.     } else {
  414.         theErr = FinishRecording (&myVars);
  415.         recording = false;
  416.         DoPlayAll(pButtonItemRef,pModifiers);
  417.         prepairedToRecord = false;
  418.         gSAL_CurrentControl = recordButton;
  419.         SAL_SetTitle ("\pSetup Rec");
  420.     }
  421.  
  422.     return theErr;
  423. }
  424.  
  425. /*-----------------------------------------------------------------------*/
  426. static pascal OSErr MuteSound1(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  427. {
  428.     OSErr    theErr;
  429.     unsigned short    leftVol, rightVol;
  430.  
  431. #pragma unused (pButtonItemRef,pModifiers)
  432.  
  433.     SetControlValue (muteCheck1, !GetControlValue (muteCheck1));
  434.     theErr = ASoundGetVolume (mySoundInfo1, &leftVol, &rightVol);
  435.     if (leftVol != 0 || rightVol != 0) {
  436.         theErr = ASoundSetVolume (mySoundInfo1, 0, 0);
  437.     } else {
  438.         theErr = ASoundSetVolume (mySoundInfo1, 0x100, 0x100);
  439.     }
  440.  
  441.     return theErr;
  442. }
  443.  
  444. /*-----------------------------------------------------------------------*/
  445. static pascal OSErr MuteSound2(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  446. {
  447.     OSErr    theErr;
  448.     unsigned short    leftVol, rightVol;
  449.  
  450. #pragma unused (pButtonItemRef,pModifiers)
  451.  
  452.     SetControlValue (muteCheck2, !GetControlValue (muteCheck2));
  453.     theErr = ASoundGetVolume (mySoundInfo2, &leftVol, &rightVol);
  454.     if (leftVol != 0 || rightVol != 0) {
  455.         theErr = ASoundSetVolume (mySoundInfo2, 0, 0);
  456.     } else {
  457.         theErr = ASoundSetVolume (mySoundInfo2, 0x100, 0x100);
  458.     }
  459.     return theErr;
  460. }
  461.  
  462. /*-----------------------------------------------------------------------*/
  463. static pascal OSErr MuteSound3(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  464. {
  465.     OSErr    theErr;
  466.     unsigned short    leftVol, rightVol;
  467.  
  468. #pragma unused (pButtonItemRef,pModifiers)
  469.  
  470.     SetControlValue (muteCheck3, !GetControlValue (muteCheck3));
  471.     theErr = ASoundGetVolume (mySoundInfo3, &leftVol, &rightVol);
  472.     if (leftVol != 0 || rightVol != 0) {
  473.         theErr = ASoundSetVolume (mySoundInfo3, 0, 0);
  474.     } else {
  475.         theErr = ASoundSetVolume (mySoundInfo3, 0x100, 0x100);
  476.     }
  477.     return theErr;
  478. }
  479.  
  480. /*-----------------------------------------------------------------------*/
  481. static pascal OSErr MuteSound4(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  482. {
  483.     OSErr    theErr;
  484.     unsigned short    leftVol, rightVol;
  485.  
  486. #pragma unused (pButtonItemRef,pModifiers)
  487.  
  488.     SetControlValue (muteCheck4, !GetControlValue (muteCheck4));
  489.     theErr = ASoundGetVolume (mySoundInfo4, &leftVol, &rightVol);
  490.     if (leftVol != 0 || rightVol != 0) {
  491.         theErr = ASoundSetVolume (mySoundInfo4, 0, 0);
  492.     } else {
  493.         theErr = ASoundSetVolume (mySoundInfo4, 0x100, 0x100);
  494.     }
  495.     return theErr;
  496. }
  497.  
  498. /*-----------------------------------------------------------------------*/
  499. static pascal OSErr MuteSound5(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  500. {
  501.     OSErr    theErr;
  502.     unsigned short    leftVol, rightVol;
  503.  
  504. #pragma unused (pButtonItemRef,pModifiers)
  505.  
  506.     SetControlValue (muteCheck5, !GetControlValue (muteCheck5));
  507.     theErr = ASoundGetVolume (mySoundInfo5, &leftVol, &rightVol);
  508.     if (leftVol != 0 || rightVol != 0) {
  509.         theErr = ASoundSetVolume (mySoundInfo5, 0, 0);
  510.     } else {
  511.         theErr = ASoundSetVolume (mySoundInfo5, 0x100, 0x100);
  512.     }
  513.     return theErr;
  514. }
  515.  
  516. /*-----------------------------------------------------------------------*/
  517. static pascal OSErr MuteSound6(const ButtonItemRef pButtonItemRef,const SInt32 pModifiers)
  518. {
  519.     OSErr    theErr;
  520.     unsigned short    leftVol, rightVol;
  521.  
  522. #pragma unused (pButtonItemRef,pModifiers)
  523.  
  524.     SetControlValue (muteCheck6, !GetControlValue (muteCheck6));
  525.     theErr = ASoundGetVolume (mySoundInfo6, &leftVol, &rightVol);
  526.     if (leftVol != 0 || rightVol != 0) {
  527.         theErr = ASoundSetVolume (mySoundInfo6, 0, 0);
  528.     } else {
  529.         theErr = ASoundSetVolume (mySoundInfo6, 0x100, 0x100);
  530.     }
  531.     return theErr;
  532. }
  533.  
  534. static pascal OSErr    ClearAllSounds (long menuResult)
  535. {
  536. #pragma unused (menuResult)
  537.     OSErr        err;
  538.  
  539.     mySoundInfo1 = ASoundNew (&err);
  540.     mySoundInfo2 = ASoundNew (&err);
  541.     mySoundInfo3 = ASoundNew (&err);
  542.     mySoundInfo4 = ASoundNew (&err);
  543.     mySoundInfo5 = ASoundNew (&err);
  544.     mySoundInfo6 = ASoundNew (&err);
  545.  
  546.     sound1Set = false;
  547.     sound2Set = false;
  548.     sound3Set = false;
  549.     sound4Set = false;
  550.     sound5Set = false;
  551.     sound6Set = false;
  552.  
  553.     gSAL_CurrentControl = playButton1;
  554.     SAL_SetTitle ("\pLoad Sound 1");
  555.     gSAL_CurrentControl = playButton2;
  556.     SAL_SetTitle ("\pLoad Sound 2");
  557.     gSAL_CurrentControl = playButton3;
  558.     SAL_SetTitle ("\pLoad Sound 3");
  559.     gSAL_CurrentControl = playButton4;
  560.     SAL_SetTitle ("\pLoad Sound 4");
  561.     gSAL_CurrentControl = playButton5;
  562.     SAL_SetTitle ("\pLoad Sound 5");
  563.     gSAL_CurrentControl = playButton6;
  564.     SAL_SetTitle ("\pLoad Sound 6");
  565.  
  566.     return err;
  567. }
  568.  
  569. /*-----------------------------------------------------------------------*/
  570.         void    main (void)
  571. {
  572.     Rect    r;
  573.     long    soundAttr;
  574.     short    err;
  575.  
  576.     SAL_InitSimpleApp (2, kSAL_UseStandardMenu);          /* Simple App Sets up the Tool Box For us */
  577.     SAL_GetDocumentWindow(128,nil);                    /* Get our stored window */
  578.  
  579.     SAL_SetRectLocation(&r, 10, 2);                    /* This Sets a rects anchor point */
  580.     SAL_SetRectDimensions(&r, 90, 20);                /* This Sets its size without changing it position */
  581.     err = SAL_InstallPushButton(1, gSAL_CurrentWindow, "\pLoad Sound 1", &r, (char)0, DoPlay1,nil);
  582.     playButton1 = gSAL_CurrentControl;
  583.  
  584.     SAL_SetRectLocation(&r, 130, 2);                /* This Sets a rects anchor point */
  585.     SAL_SetRectDimensions(&r, 90, 20);                /* This Sets its size without changing it position */
  586.     err = SAL_InstallPushButton (2, gSAL_CurrentWindow, "\pLoad Sound 2", &r, (char)0, DoPlay2,nil);
  587.     playButton2 = gSAL_CurrentControl;
  588.  
  589.     SAL_SetRectLocation (&r, 270, 2);                /* This Sets a rects anchor point */
  590.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  591.     err = SAL_InstallPushButton (3, gSAL_CurrentWindow, "\pLoad Sound 3", &r, (char)0, DoPlay3,nil);
  592.     playButton3 = gSAL_CurrentControl;
  593.  
  594.     SAL_SetRectLocation (&r, 10, 25);                /* This Sets a rects anchor point */
  595.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  596.     err = SAL_InstallPushButton (4, gSAL_CurrentWindow, "\pLoad Sound 4", &r, (char)0, DoPlay4,nil);
  597.     playButton4 = gSAL_CurrentControl;
  598.  
  599.     SAL_SetRectLocation (&r, 130, 25);                /* This Sets a rects anchor point */
  600.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  601.     err = SAL_InstallPushButton (5, gSAL_CurrentWindow, "\pLoad Sound 5", &r, (char)0, DoPlay5,nil);
  602.     playButton5 = gSAL_CurrentControl;
  603.  
  604.     SAL_SetRectLocation (&r, 270, 25);                /* This Sets a rects anchor point */
  605.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  606.     err = SAL_InstallPushButton (6, gSAL_CurrentWindow, "\pLoad Sound 6", &r, (char)0, DoPlay6,nil);
  607.     playButton6 = gSAL_CurrentControl;
  608.  
  609.     SAL_SetRectLocation (&r, 10, 50);                /* This Sets a rects anchor point */
  610.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  611.     err = SAL_InstallPushButton (7, gSAL_CurrentWindow, "\pSetup Rec", &r, (char)0, DoRecord,nil);
  612.     recordButton = gSAL_CurrentControl;
  613.  
  614.     SAL_SetRectLocation (&r, 110, 80);                /* This Sets a rects anchor point */
  615.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  616.     err = SAL_InstallPushButton (8, gSAL_CurrentWindow, "\pPlay All", &r, (char)0, DoPlayAll,nil);
  617.     playAllButton = gSAL_CurrentControl;
  618.  
  619.     SAL_SetRectLocation (&r, 110, 2);                /* This Sets a rects anchor point */
  620.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  621.     err = SAL_InstallCheckBox (9, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound1,nil);
  622.     muteCheck1 = gSAL_CurrentControl;
  623.  
  624.     SAL_SetRectLocation (&r, 250, 2);                /* This Sets a rects anchor point */
  625.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  626.     err = SAL_InstallCheckBox (10, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound2,nil);
  627.     muteCheck2 = gSAL_CurrentControl;
  628.  
  629.     SAL_SetRectLocation (&r, 370, 2);                /* This Sets a rects anchor point */
  630.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  631.     err = SAL_InstallCheckBox (11, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound3,nil);
  632.     muteCheck3 = gSAL_CurrentControl;
  633.  
  634.     SAL_SetRectLocation (&r, 110, 25);                /* This Sets a rects anchor point */
  635.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  636.     err = SAL_InstallCheckBox (12, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound4,nil);
  637.     muteCheck4 = gSAL_CurrentControl;
  638.  
  639.     SAL_SetRectLocation (&r, 250, 25);                /* This Sets a rects anchor point */
  640.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  641.     err = SAL_InstallCheckBox (13, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound5,nil);
  642.     muteCheck5 = gSAL_CurrentControl;
  643.  
  644.     SAL_SetRectLocation (&r, 370, 25);                /* This Sets a rects anchor point */
  645.     SAL_SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  646.     err = SAL_InstallCheckBox (14, gSAL_CurrentWindow, "\p", &r , (char)0, 1, MuteSound6,nil);
  647.     muteCheck6 = gSAL_CurrentControl;
  648.  
  649.     mySoundInfo1 = ASoundNew (&err);
  650.     if (err == noErr)
  651.         mySoundInfo2 = ASoundNew (&err);
  652.     if (err == noErr)
  653.         mySoundInfo3 = ASoundNew (&err);
  654.     if (err == noErr)
  655.         mySoundInfo4 = ASoundNew (&err);
  656.     if (err == noErr)
  657.         mySoundInfo5 = ASoundNew (&err);
  658.     if (err == noErr)
  659.         mySoundInfo6 = ASoundNew (&err);
  660.  
  661.     SAL_InstallMenuItem (130, 9, "\pClear all sounds", 0, 'R', ClearAllSounds, nil);
  662.     SAL_InstallIdleProc(MyIdleProc);
  663.  
  664.     err = Gestalt (gestaltSoundAttr, &soundAttr);
  665.     if ((soundAttr & (1 << gestaltPlayAndRecord)) == false) {
  666.         DebugStr ("\pCan't play and record simultaniously.");
  667.     }
  668.  
  669.     if (err == noErr)
  670.         SAL_Run();                                 /* Let SimpleApp handle the rest */
  671. }
  672.  
  673. // utility functions since I already keep the control handle around
  674. /*-----------------------------------------------------------------------*/
  675. static void EnableControl (ControlRef cr)
  676. {
  677.     if (cr != nil) {
  678.         HiliteControl(cr, nil);
  679.     }
  680. }
  681.  
  682. /*-----------------------------------------------------------------------*/
  683. static void DisableControl (ControlRef cr)
  684. {
  685.     if (cr != nil) {
  686.         HiliteControl(cr, 255);
  687.     }
  688. }
  689.